//
//  ConfigManager.m
//  PigMarket
//
//  Created by Felix on 2019/4/11.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "ConfigManager.h"
#import "PropertyListUtil.h"

@interface ConfigManager ()

@property(strong, nonatomic)NSDictionary *rootDic;

@end

@implementation ConfigManager

+(instancetype)sharedInstance {
    
    static ConfigManager *instance = nil;
    static dispatch_once_t token;
    
    dispatch_once(&token,^{
        if(instance == nil){
            instance = [[ConfigManager alloc]init];
        }
    } );
    
    return instance;
}

- (NSString *)environment {
    if (!_environment) {
        _environment = ((NSString*)self.rootDic[@"Environment"]);
    }
    
    return _environment;
}

-(NSDictionary *)rootDic {
    if (!_rootDic) {
        _rootDic = [PropertyListUtil getRootWithName:@"CommonConfig"];
//        _rootDic = [PropertyListUtil decodePlistWithName:@"abc"];
    }
    return _rootDic;
}

- (id)getDataWithKey:(NSString *)key {
    return [PropertyListUtil getDataWithRoot:self.rootDic key:key];
}

@end
